package weifei.web;


import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;


@Data
public class Result
{

    public enum Type
    {
        Success,        // 成功
        Failed,         // 失败
        Exception       // 异常
    }


    private final Type type;
    private final String message;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private final java.util.Date time = new java.util.Date();
    private final Object data;


    public Result(Type type, String message, Object data)
    {
        this.type = type;
        this.message = message;
        this.data = data;
    }


    public static Result success(String message)
    {
        return new Result(Type.Success, message, null);
    }
    public static Result success(String message, Object data)
    {
        return new Result(Type.Success, message, data);
    }


    public static Result failed(String message)
    {
        return new Result(Type.Failed, message, null);
    }
    public static Result failed(String message, Object data)
    {
        return new Result(Type.Failed, message, data);
    }


    public static Result exception(String message)
    {
        return new Result(Type.Exception, message, null);
    }
    public static Result exception(String message, Object data)
    {
        return new Result(Type.Exception, message, data);
    }
}


